<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form-model :model="queryParam">
        <a-row>
          <a-col :span="6">
            <div style="margin-right: 12px">
              <a-form-model-item prop="udi"
                ><a-input v-model="queryParam.udi" placeholder="请输入条码" allowClear />
              </a-form-model-item>
            </div>
          </a-col>
          <a-col :span="6">
            <div style="margin-right: 12px">
              <a-form-model-item prop="batch"
                ><a-input v-model="queryParam.batch" placeholder="请输入批号" allowClear />
              </a-form-model-item>
            </div>
          </a-col>
          <a-col :span="6">
            <div style="margin-right: 12px">
              <a-form-model-item prop="productSpec"
                ><a-input v-model="queryParam.productSpec" placeholder="请输入产品规格" allowClear />
              </a-form-model-item>
            </div>
          </a-col>  
          <a-col :span="6">
            <div style="margin-right: 12px">
              <a-form-model-item prop="state">
                <a-select
                  v-model="queryParam.state"
                  style="width: 100%; margin-top: 4px"
                  placeholder="请选择商品状态"
                  allowClear
                >
                  <a-select-option v-for="(item, index) in goodStateOptions" :key="index" :value="item.value">
                    {{ item.label }}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </div>
          </a-col>
          <a-col :span="6" style="margin-top: 5px">
            <a-button style="margin-right: 20px" @click="searchQuery()" type="primary"> 查询 </a-button>
            <a-button style="margin-right: 20px" @click="searchReset()"> 重置 </a-button>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="6">
            <div style="margin-right: 12px">
              <a-form-model-item prop="warehourse">
                <a-select
                  v-model="queryParam.warehourse"
                  style="width: 100%; margin-top: 4px"
                  placeholder="请选择所属仓库"
                  allowClear
                >
                  <a-select-option v-for="(item, index) in warehouseOptions" :key="index" :value="item.value">
                    {{ item.label }}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </div>
          </a-col>
          <a-col :span="18">
            <div class="table-operator" style="margin-top: 5px">
              <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button> -->
              <a-button type="primary" icon="download" @click="handleExportXls('wms_product')">导出</a-button>
              <a-upload
                name="file"
                :showUploadList="false"
                :multiple="false"
                :headers="tokenHeader"
                :action="importExcelUrl"
                @change="handleImportExcel"
              >
                <a-button type="primary" icon="import">导入</a-button>
              </a-upload>
              <!-- 高级查询区域 -->
              <j-super-query
                :fieldList="superFieldList"
                ref="superQueryModal"
                @handleSuperQuery="handleSuperQuery"
              ></j-super-query>
              <!-- <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown> -->
            </div>
          </a-col>
        </a-row>
      </a-form-model>
      <!-- <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24"> </a-row>
      </a-form> -->
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="warehourse" slot-scope="text">
          {{ handleWarehourse(text) }}
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <template slot="state" slot-scope="text">
          <a-tag :color="onColor(text)">
            {{ OnStatue(text) }}
          </a-tag>
        </template>
        <span slot="action" slot-scope="text, record">
          <!-- <a @click="handleEdit(record)">编辑</a> -->
          <a @click="handleDetail(record)">详情</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item @click="seeTrack(record)"> 轨迹 </a-menu-item>
              <!-- <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item> -->
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>

    <wms-product-modal ref="modalForm" @ok="modalFormOk"></wms-product-modal>
    <modal-good-track ref="trackModal"></modal-good-track>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import WmsProductModal from './modules/WmsProductModal'
import ModalGoodTrack from './components/modal-good-track'
import { mapState, mapGetters } from 'vuex'
import { stateObjToArray } from '@/utils/common.js'
import { queryGoodTrack } from '@/api/good.js'
export default {
  name: 'WmsProductList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    WmsProductModal,
    ModalGoodTrack,
  },
  data() {
    return {
      description: 'wms_product管理页面',
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '产品规格',
          align: 'center',
          dataIndex: 'productSpec',
        },
        {
          title: '产品名称',
          align: 'center',
          dataIndex: 'productName',
        },
        {
          title: '商品状态',
          align: 'center',
          // dataIndex: 'state',
          scopedSlots: { customRender: 'state' },
        },
        {
          title: '更新时间',
          align: 'center',
          dataIndex: 'updateTime',
          
        },
        {
          title: '出库时间',
          align: 'center',
          dataIndex: 'outTime',
        },



        // {
        //   title: '商品类型',
        //   align: 'center',
        //   // dataIndex: 'productType',
        //   scopedSlots: { customRender: 'productType' },
        // },
        // {
        //   title: '所属仓库',
        //   align: 'center',
        //   scopedSlots: { customRender: 'warehourse' },
        // },
        {
          title: '仓库库位ID',
          align: 'center',
          dataIndex: 'warePid',
        },
        {
          title: '批号',
          align: 'center',
          dataIndex: 'batch',
        },
        // {
        //   title: '公司',
        //   align: 'center',
        //   dataIndex: 'companyTo',
        // },
        {
          title: '商品条码',
          align: 'center',
          dataIndex: 'udi',
        },
        // {
        //   title:'所属公司',
        //   align:"center",
        //   dataIndex: 'company'
        // },
        {
          title: '最小产品单元产品标识',
          align: 'center',
          dataIndex: 'productZxxsdycpbs',
        },
        {
          title: '医疗器械唯一标识编码体系名称',
          align: 'center',
          dataIndex: 'productCpbsbmtxmc',
        },

        // {
        //   title:'出库标识位',
        //   align:"center",
        //   dataIndex: 'outFlag'
        // },
        // {
        //   title:'出借标识位',
        //   align:"center",
        //   dataIndex: 'lendFlag'
        // },
        // {
        //   title:'调拨标识位  调拨一次+1',
        //   align:"center",
        //   dataIndex: 'allocationFlag'
        // },
        {
          title: '商品编号',
          align: 'center',
          dataIndex: 'productNo',
        },

        {
          title: '箱条码',
          align: 'center',
          dataIndex: 'boxId',
        },
        {
          title: '箱子条码',
          align: 'center',
          dataIndex: 'boxBar',
        },
        // {
        //   title:'订单id',
        //   align:"center",
        //   dataIndex: 'orderId'
        // },
        {
          title: '订单号',
          align: 'center',
          dataIndex: 'orderNo',
        },
        // {
        //   title:'订单类型',
        //   align:"center",
        //   dataIndex: 'orderType'
        // },

        {
          title: '当前操作人',
          align: 'center',
          dataIndex: 'operator',
        },
        {
          title: '最小销售单元中使用单元的数量',
          align: 'center',
          dataIndex: 'productZxxsydydsl',
        },
        {
          title: '医疗注册人/备案人名称',
          align: 'center',
          dataIndex: 'productYlqxzcrbarmc',
        },
        {
          title: '仓库库区ID',
          align: 'center',
          dataIndex: 'wareRid',
        },
        {
          title: '所属过道',
          align: 'center',
          dataIndex: 'wareAid',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 80,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/wms/wmsProduct/list',
        delete: '/wms/wmsProduct/delete',
        deleteBatch: '/wms/wmsProduct/deleteBatch',
        exportXlsUrl: '/wms/wmsProduct/exportXls',
        importExcelUrl: 'wms/wmsProduct/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
      disableMixinCreated: true,
    }
  },
  created() {
    // this.getSuperFieldList()
    this.$store.commit('getEnableWarehouse')
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
    ...mapGetters(['userInfo']),
    ...mapState({
      goodStates: (s) => s.order.goodStates,
      goodStateOptions: (s) => stateObjToArray(s.order.goodStates),
      warehouseOptions: (s) => {
        return stateObjToArray(s.dictionary.enableWarehouse)
      },
      enableWarehouse: (s) => s.dictionary.enableWarehouse,
    }),
  },
  mounted() {
    this.$set(this.queryParam, 'warehourse', this.userInfo.currWarehouse)
    this.searchQuery()
  },
  methods: {
    async seeTrack(e) {
      try {
        const params = { orderNo: e.id }
        const r = await queryGoodTrack(params)
        const o = {
          items: r.result.map((e) => {
            return {
              time: e.createTime,
              operator: e.createBy,
              content: e.content,
            }
          }),
        }
        console.log('-123123123213', o)
        this.$refs.trackModal.open(o)
      } catch (_) {}
    },
    searchReset() {
      this.$set(this.queryParam, 'udi', undefined)
      this.$set(this.queryParam, 'batch', undefined)
      this.$set(this.queryParam, 'productSpec', undefined)
      this.$set(this.queryParam, 'state', undefined)
      this.$set(this.queryParam, 'warehourse', undefined)
    },
    initDictConfig() {},
    handleWarehourse(e) {
      const row = this.enableWarehouse[e.warehourse]
      if (row) {
        return row.text
      } else {
        return ''
      }
    },
    // getSuperFieldList() {
    //   let fieldList = []
    //   fieldList.push({ type: 'string', value: 'productNo', text: '商品编号' })
    //   fieldList.push({ type: 'string', value: 'productType', text: '商品类型' })
    //   fieldList.push({ type: 'string', value: 'boxId', text: '箱条码' })
    //   fieldList.push({ type: 'string', value: 'boxBar', text: '箱子条码' })
    //   fieldList.push({ type: 'string', value: 'orderId', text: '订单id' })
    //   fieldList.push({ type: 'string', value: 'orderNo', text: '订单号' })
    //   fieldList.push({ type: 'string', value: 'orderType', text: '订单类型' })
    //   fieldList.push({ type: 'string', value: 'state', text: '商品状态' })
    //   fieldList.push({ type: 'string', value: 'operator', text: '当前操作人' })
    //   fieldList.push({ type: 'string', value: 'companyTo', text: '公司' })
    //   fieldList.push({ type: 'string', value: 'company', text: '所属公司' })
    //   fieldList.push({ type: 'string', value: 'productSpec', text: '产品规格' })
    //   fieldList.push({ type: 'string', value: 'productName', text: '产品名称' })
    //   fieldList.push({ type: 'string', value: 'productZxxsdycpbs', text: '最小产品单元产品标识' })
    //   fieldList.push({ type: 'string', value: 'productCpbsbmtxmc', text: '医疗器械唯一标识编码体系名称' })
    //   fieldList.push({ type: 'int', value: 'productZxxsydydsl', text: '最小销售单元中使用单元的数量' })
    //   fieldList.push({ type: 'string', value: 'productYlqxzcrbarmc', text: '医疗注册人/备案人名称' })
    //   fieldList.push({ type: 'string', value: 'outFlag', text: '出库标识位' })
    //   fieldList.push({ type: 'string', value: 'lendFlag', text: '出借标识位' })
    //   fieldList.push({ type: 'int', value: 'allocationFlag', text: '调拨标识位  调拨一次+1' })
    //   fieldList.push({ type: 'string', value: 'warePid', text: '仓库库位ID' })
    //   fieldList.push({ type: 'string', value: 'wareRid', text: '仓库库区ID' })
    //   fieldList.push({ type: 'string', value: 'wareAid', text: '所属过道' })
    //   fieldList.push({ type: 'string', value: 'warehourse', text: '所属仓库' })
    //   this.superFieldList = fieldList
    // },
    onColor({ state }) {
      const o = this.goodStates[state]
      if (o) {
        return o.color
      } else {
        return ''
      }
    },
    OnStatue({ state }) {
      const o = this.goodStates[state]
      if (o) {
        return o.text
      } else {
        return ''
      }
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>